import com.fasterxml.jackson.databind.ObjectMapper;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
@WebServlet(name="/querylike",urlPatterns = "/querylike")
public class QueryLike extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        //获取前端参数
        String sno = req.getParameter("sno");
        String sname = req.getParameter("sname");
        String sgrade = req.getParameter("sgrade");
        //设置中文
        resp.setContentType("text/html;charset=utf-8");
        //获取写的对象
        PrintWriter writer = resp.getWriter();
        //写内容
        List<Student> query = StudentDAO.queryLike(sno,sname,sgrade);
        ObjectMapper mapper = new ObjectMapper(); // create once, reuse
        String json = mapper.writeValueAsString(query);
        writer.write(json);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        this.doPost(req, resp);
    }
}
